<%-- 
    Document   : risultatoRicerca
    Created on : 9-ago-2010, 15.33.04
    Author     : edoardo
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<jsp:useBean id="loginForm"
	class="com.setup.trac.pojo.wrappers.UtentiView" scope="session"></jsp:useBean>
<%
	try {

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<%@page import="com.setup.trac.pojo.wrappers.UtentiView"%>
<%@page import="com.setup.trac.pojo.wrappers.TicketView"%><html
	xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Elenco Tickets</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="webmasterneo" />
<meta name="description"
	content="A short description of your site here." />
<link rel="stylesheet" href="style.css" type="text/css" />
<!--<style type="text/css">
#overlay {
     visibility: hidden;
     position: absolute;
     left: 0px;
     top: 300px;
     opacity:0.4;
     filter:alpha(opacity=30);
     width:40%;
     height:40%;
     text-align:center;
     z-index: 400;
     background-color: silver;
     
}

#imageOverlay {
		
}
</style>-->
<script type="text/javascript" src="scripts/prototype.js"></script>
<script type="text/javascript" src="scripts/tts.js"></script>
<script type="text/javascript" language="javascript1.5">

<%int formNumber = 0;
				if (loginForm.getUtenti().getProfilo().getDescrizione()
						.equalsIgnoreCase("DEVELOPER") || loginForm.getUtenti().getProfilo().getDescrizione()
						.equalsIgnoreCase("ADMINISTRATOR")) {
					formNumber = 1;
				}%>
function visualizzaStorico(aCheckBox){
	var theId = aCheckBox.value;
	$(aCheckBox.value).style.background='#CCCCCC';
	var arrayIds = document.forms[<%=formNumber%>].idTicket;
	for(i=0;i<arrayIds.length;i++){
		if(arrayIds[i].value!=theId){
			$(arrayIds[i].value).style.background='none';
		}
	}
	$('overlay').style.visibility='visible';
    $('dettaglioTicket').style.visibility='hidden'
	new Ajax.Request('dettaglioTicket.do?id='+theId,
			  {
			    method:'get',
			    onSuccess: function(transport){
			      var response = transport.responseText || "no response text";
			      $('overlay').style.visibility='hidden'
			      $('dettaglioTicket').innerHTML=response;
			      $('dettaglioTicket').style.visibility='visible'
				      
			    },
			    onFailure: function(){  }
			  });

}

function eliminaTicket(idTicket){
	new Ajax.Request('cancellaTicket.do?idTicket='+idTicket,
			  {
			    method:'get',
			    onSuccess: function(transport){
			      var response = transport.responseText || "no response text";
			      if(response && response=="true"){
				      alert("Il ticket è stato cancellato");
				      document.location.href="search.do";
				  }
			         
			    },
			    onFailure: function(){  }
			  });
	
}
</script>
</head>

<body>

<div id="header">
<div class="header"></div>
</div>


<div id="menu"><c:choose>
	<c:when test="${loginForm.utenti.profilo.descrizione=='USER'}">
		<div class="menu"><a href="modificaUtente.do">modifica profilo</a></div>
		<div class="menu"><a href="inserisciTicket.do">Nuovo ticket</a></div>
		<div class="menu"><a href="esci.do">esci</a></div>
	</c:when>
	<c:otherwise>
		<c:choose>
			<c:when test="${loginForm.utenti.profilo.descrizione=='DEVELOPER' }">
				<div class="menu"><a href="modificaUtente.do">modifica profilo</a></div>
				<div class="menu"><a href="esci.do">esci</a></div>
			</c:when>
			<c:otherwise>
				<div class="menu"><a href="wizardCreateUser.do">Crea utente</a></div>
				<div class="menu"><a href="listaUtenti.do">Elenco utenti</a></div>
				<div class="menu"><a href="search.do">Elenco ticket</a></div>
				<div class="menu"><a href="#" onclick="javascript:{alert('Coming soon...');return;}">Crea Progetto</a></div>
				<div class="menu"><a href="esci.do">esci</a></div><div class="menu"></div>
			</c:otherwise>
		</c:choose>
	</c:otherwise>
</c:choose>
<div class="menu"></div>
<div class="menu"></div>
<div class="menu"></div>
</div>

<div id="body"><!-- div class="submenu"><a href="#">Sub Menu1</a> / <a href="#">Sub Menu2</a> / <a href="#">Sub Menu3</a></div-->
<div class="spacer"></div>
<div class="content"><c:if
	test="${loginForm.utenti.profilo.descrizione=='DEVELOPER' || loginForm.utenti.profilo.descrizione=='ADMINISTRATOR' }">
	<form action="search.do" method="post">
	<table border="0">
		<tr>
			<td>Progetto</td>
			<td><select name="searchByProject">
				<option value="-1">--Seleziona filtro--</option>
				<c:forEach items="${progetti}" var="item">
					<option value="<c:out value="${item.idProgetto}"/>"
						<c:if test="${item.idProgetto==param.searchByProject}">selected="selected"</c:if>><c:out
						value="${item.descrizione}" /></option>
				</c:forEach>
			</select></td>
			<td>Stato ticket</td>

			<td><select name="searchByStato">
				<option value="-1">--Seleziona filtro--</option>
				<c:forEach items="${stati}" var="item">
					<option value="<c:out value="${item.stati.idStato}"/>"
						<c:if test="${item.stati.idStato==param.searchByStato}">selected="selected"</c:if>><c:out
						value="${item.stati.descrizione}" /></option>
				</c:forEach>

			</select></td>
			<tr>
				<td>Assegnati a</td>
				<td><select name="searchByOwner">
					<option value="-1">--Seleziona filtro--</option>
					<c:forEach items="${developerList}" var="item">
						<option value="<c:out value="${item.idUtente}"/>"
							<c:if test="${item.idUtente==param.searchByOwner}">selected="selected"</c:if>><c:out
							value="${item.cognome}" /> <c:out value="${item.nome}" /></option>
					</c:forEach>

				</select></td>
				<td>Inseriti da</td>
				<td><select name="searchByCliente">
					<option value="-1">--Seleziona filtro--</option>
					<c:forEach items="${usersList}" var="item">
						<option value="<c:out value="${item.idUtente}"/>"
							<c:if test="${item.idUtente==param.searchByCliente}">selected="selected"</c:if>><c:out
							value="${item.cognome}" /> <c:out value="${item.nome}" /></option>
					</c:forEach>

				</select></td>
			</tr>
			<tr>
				<td><input type="submit" name="filtraTicket"
					value="Applica filtro" /></td>
				<td><input type="button" name="eliminaFiltro"
					value="Elimina filtro" onclick="javascript:window.location.href='search.do'"/></td>
			</tr>
		</tr>

	</table>
	</form>
</c:if> <c:choose>

	<c:when test="${not empty risultatoRicercaTicket}">
		<table width="100%" cellspacing="0">
			<tr style="border-bottom: thin">
				<th></th>
				<th>Titolo</th>
				<th>Inserito il</th>
				<th>Stato</th>
				<th>Inserito da</th>
				<th>Ultima modifica</th>
				<th>Modificato da</th>
				<th>Assegnato a</th>
				<th>Allegati</th>
				<th></th>
				
			</tr>

			<form action="get">
			<c:forEach items="${risultatoRicercaTicket}" var="item">
				<tr id="<c:out value="${item.tickets.idTicket}"/>">
					<td>
					<c:if test="${loginForm.utenti.profilo.descrizione!='ADMINISTRATOR' }">
					<input type="radio" name="idTicket"
						value="<c:out value="${item.tickets.idTicket}"/>"
						onclick="javascript:visualizzaStorico(this);" />
					</c:if>
					</td>
					<td><c:out value="${item.tickets.titoloTicket}" /></td>
					<td><fmt:formatDate pattern="dd/MM/yyyy"
						value="${item.tickets.dataInserimento}" /></td>
					<td><c:out value="${item.tickets.stati.descrizione}" /></td>
					<td><c:out value="${item.tickets.utentiByIdUtente.nome}" /> <c:out
						value="${item.tickets.utentiByIdUtente.cognome}" /></td>
					<td><fmt:formatDate pattern="dd/MM/yyyy"
						value="${item.tickets.dataUltimaModifica}" /></td>
					<td><c:out
						value="${item.tickets.utentiByIdUtenteUltimaModifica.nome}" /> <c:out
						value="${item.tickets.utentiByIdUtenteUltimaModifica.cognome}" /></td>
					<td><c:out value="${item.tickets.utentiByIdOwner.nome}" /> <c:out
						value="${item.tickets.utentiByIdOwner.cognome}" /></td>
					<td><c:if test="${not empty item.tickets.allegatis}">
						<a
							href="visualizzaListaAllegati.do?id=<c:out value="${item.tickets.idTicket }"/>"
							target="_blank">Visualizza</a>
					</c:if></td>
					<td>
					<c:if test="${loginForm.utenti.idUtente==item.tickets.utentiByIdUtente.idUtente && item.tickets.stati.idStato==1}">
					<a href="javascript:eliminaTicket('<c:out value="${item.tickets.idTicket }"/>')">
					Elimina
					</a>
					</c:if>
					<c:if test="${loginForm.utenti.profilo.descrizione=='ADMINISTRATOR' && (item.tickets.stati.idStato==2 || item.tickets.stati.idStato==3)}">
						<a href="dettaglioIntervento.do?idTicket=<c:out value='${item.tickets.idTicket }'/>&idProgetto=<c:out value='${item.tickets.idProgetto }'/>"  target="_blank">Calcola consuntivo</a>
					</c:if>					
					</td>
				</tr>
			</c:forEach>
			</form>
			<%
				boolean filtra = request.getParameter("filtraTicket")!=null;
				String sFiltraParam = "";
				if(filtra){
					sFiltraParam="&filtraTicket=true&searchByProject="+request.getParameter("searchByProject")+"&searchByStato="+request.getParameter("searchByStato")+"&searchByOwner="+request.getParameter("searchByOwner")+"&searchByCliente="+request.getParameter("searchByCliente");
				}
				request.setAttribute("filtraTicketParam",sFiltraParam);
			%>
			<table>
				<tr>
					<td align="right"><c:if test="${!currentPage.firstPage }">
						<a href="search.do?p=<c:out value='${prevPage }' />&action=prev<c:out value='${filtraTicketParam }'/>">prev</a>
					</c:if> <c:if test="${!currentPage.firstPage && !currentPage.lastPage }">	
				|</c:if> <c:if test="${!currentPage.lastPage }">
						<a href="search.do?p=<c:out value='${nextPage }' />&action=next<c:out value='${filtraTicketParam }'/>">next</a>
					</c:if></td>
					<td>Pagina <c:out value="${currentPage.page }" /> di <c:out
						value="${currentPage.pagineTotali}" /></td>
				</tr>
			</table>
		</table>
	</c:when>
	<c:otherwise>
		Nessun ticket trovato
	</c:otherwise>
</c:choose>

<div id="overlay" style="visibility: hidden;"><img
	src="img/loading.gif" /> <!--<div id="imageOverlay" >
			
		</div>--> <%-- Qui ci va il dettaglio del ticket --%></div>

<div id="dettaglioTicket" style="visibility: hidden"></div>
</body>

</html>
<%
	} catch (Exception e) {
		e.printStackTrace();
	}
%>
